package com.gumbou.mis.pos.service.impl;

import com.gumbou.mis.pos.entity.PosOrder;
import com.gumbou.mis.pos.mapper.PosOrderMapper;
import com.gumbou.mis.pos.service.PosOrderService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (PosOrder)表服务实现类
 *
 * @author makejava
 * @since 2021-11-09 20:09:16
 */
@Service("posOrderService")
public class PosOrderServiceImpl implements PosOrderService {
    @Resource
    private PosOrderMapper posOrderMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param orderId 主键
     * @return 实例对象
     */
    @Override
    public PosOrder queryById(Integer orderId) {
        return this.posOrderMapper.queryById(orderId);
    }

    /**
     * 分页查询
     *
     * @param posOrder 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<PosOrder> queryByPage(PosOrder posOrder, PageRequest pageRequest) {
        long total = this.posOrderMapper.count(posOrder);
        return new PageImpl<>(this.posOrderMapper.queryAllByLimit(posOrder, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param posOrder 实例对象
     * @return 实例对象
     */
    @Override
    public PosOrder insert(PosOrder posOrder) {
        this.posOrderMapper.insert(posOrder);
        return posOrder;
    }

    /**
     * 修改数据
     *
     * @param posOrder 实例对象
     * @return 实例对象
     */
    @Override
    public PosOrder update(PosOrder posOrder) {
        this.posOrderMapper.update(posOrder);
        return this.queryById(posOrder.getOrderId());
    }

    /**
     * 通过主键删除数据
     *
     * @param orderId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer orderId) {
        return this.posOrderMapper.deleteById(orderId) > 0;
    }
}
